﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using myschoolDal;

namespace school
{
    public partial class manchangestuclassgrades : Form
    {
        private string term;
        private string major;
        private string course;
        private long ID;
        private string name;
        private int score;

        public manchangestuclassgrades()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 修改学生成绩
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //检查输入框是否正确            
            if (this.comboBox1.Text == "" || this.comboBox2.Text == "" || textBox2.Text == "" || textBox9.Text == "" || textBox5.Text == "" || textBox3.Text == "")
            {
                MessageBox.Show("错误：" + bug.Class1.worng4001 + " \n错误代码：Wrong4001", "提示");
            }
            else
            {
                //获取输入的值
                term = comboBox1.SelectedItem.ToString();
                major = comboBox2.SelectedItem.ToString();
                course = textBox2.Text.ToString();
                score = Convert.ToInt32(textBox3.Text);

                //检查学号与姓名的输入
                if (textBox9.Text == "" && textBox5.Text != "")
                {
                    name = textBox5.Text.Trim();
                    ID = manserver.GetStuInformationID(name, major);
                    //没做姓名，专业的检查，输入时要注意
                    textBox9.Text = ID.ToString();
                }
                else if (textBox9.Text != "" && textBox5.Text == "")
                {
                    ID = Convert.ToInt64(textBox9.Text);
                    if (stuservers.CheckID(ID))
                    {
                        name = manserver.GetStuInformationName(ID);
                    }
                    textBox5.Text = name;
                }
                else if (textBox9.Text == "" && textBox5.Text == "")
                {
                    MessageBox.Show("错误：" + bug.Class1.worng4001 + " \n错误代码：Wrong4001", "提示");
                }
                else if (textBox9.Text != "" && textBox5.Text != "")
                {
                    name = textBox5.Text.Trim();
                    ID = Convert.ToInt64(textBox9.Text);
                    if (name != manserver.GetStuInformationName(ID))
                    {
                        name = manserver.GetStuInformationName(ID);
                    }
                };
                if (manserver.ManSourceCheck(course))
                {
                    manserver.ManChangeStuSources(course, ID, term, major, score);
                }
                else
                {
                    MessageBox.Show("错误：课程不存在！", "提示");
                }

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void source(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
